package options.view;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.UIManager;

public class ViewSettings {
	private static ViewSettings view = null;
	@SuppressWarnings("unused")
	private static final String iconFile32 = "images" + File.separator + "icon32.png";
	private static final String iconFile16 = "images" + File.separator + "Monitor.png";
	private Image image = null;
	private Icon icon = null;

	private ViewSettings() {
	}

	/**
	 * Ritorna una istanza di questa classe
	 * 
	 * @return
	 */
	public static ViewSettings getSettings() {
		if (view == null) {
			view = new ViewSettings();
		}

		return view;
	}

	/**
	 * Center the dialog on the screen
	 * 
	 * @return void
	 */
	public void centerDialog(Container container) {
		Dimension dialogSize = container.getSize();
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		container.setLocation(screenSize.width / 2 - dialogSize.width / 2, screenSize.height / 2
				- dialogSize.height / 2);
	}

	/**
	 * Imposta l'icona del Frame che viene passato come argomento
	 * 
	 * @param frame
	 */
	public void setIcon(Frame frame) {
		if (image == null)
			image = Toolkit.getDefaultToolkit().getImage(iconFile16);

		frame.setIconImage(image);
	}

	/**
	 * Imposta l'aspetto del Container come quello di default del sistema
	 * 
	 * @param container
	 */
	public void setLookAndFeel(Container container) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception exc) {
			System.err.println("Exception setting look & feel: " + exc);
		}
	}

	/**
	 * Ritorna l'icona di defualt del sistema in uso
	 */
	public ImageIcon getImageIcon() {
		if (icon == null) {
			icon = new ImageIcon(Toolkit.getDefaultToolkit().getImage(iconFile32));
		}

		return (ImageIcon) icon;
	}
}
